package dba

import (
	"MBTIx/models"

	"github.com/jmoiron/sqlx"
)

func SelectProByProId(db *sqlx.DB,pro_id string, problem *models.Problem){
	db.Get(problem,
			`select t1.pro_id,t1.pro_order,t1.pro_description,
			t1.mold_id
			from problem t1
			where pro_id = $1 `,pro_id)
	GetOptionByProId(db,(*problem).Pro_id,&((*problem).Options))
	(*problem).OptionA = (*problem).Options[0].Op_description;
	(*problem).OptionB = (*problem).Options[1].Op_description;
	(*problem).AnswerA = (*problem).Options[0].Answer;
	(*problem).AnswerB = (*problem).Options[1].Answer;
	GetMoldDesc(db,(*problem).Mold_id, &(*problem).Mold_description)
}
func SelectAllPro(db *sqlx.DB, problems *[]models.Problem){
	db.Select(problems,
			`select t1.pro_id,t1.pro_order,t1.pro_description,
			t1.mold_id
			from problem t1
			order by pro_id`)
	for i,n := 0,len(*problems) ; i < n; i++ {
		GetOptionByProId(db,(*problems)[i].Pro_id,&((*problems)[i].Options))
		(*problems)[i].OptionA = (*problems)[i].Options[0].Op_description;
		(*problems)[i].OptionB = (*problems)[i].Options[1].Op_description;
		(*problems)[i].AnswerA = (*problems)[i].Options[0].Answer;
		(*problems)[i].AnswerB = (*problems)[i].Options[1].Answer;
	}
}